<template>
  <div>
    <el-tag
      v-for="(p, index) in breadData"
      :key="index"
      :closable="p.path != '/main/home'"
      :effect="p.path == $route.path ? 'dark' : 'light'"
      @click="$router.push(p.path)"
      @close="minusBread(index)"
      size="small"
    >
      {{ p.name }}
    </el-tag>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "tag",
  computed: {
    ...mapState("bread", ["breadData"]),
  },
  methods: {
    minusBread(index) {
      if (this.breadData.length == 2) {
        this.$router.push("/main/home");
      } else {
        if (this.breadData[index + 1]) {
          this.$router.push(this.breadData[index + 1].path);
        } else {
          this.$router.push(this.breadData[index - 1].path);
        }
      }
      this.$store.commit("bread/MINBREADDATA", index);
    },
  },
};
</script>

<style scoped lang='less'>
.el-tag {
  margin-bottom: 5px;
  cursor: pointer;
}
</style>